use anyhow::Result;
use napi_derive_ohos::napi;
use std::fs;

use crate::mime_info::MimeInfo;

#[napi]
pub async fn detect(file_path: String) -> Result<MimeInfo> {
    let file = fs::File::open(&file_path)?;
    let mime_type = mimetype::detech_from_reader(&file);
    let mime = mime_type.mime;
    let extension = mime_type.extension;
    let aliases = mime_type.aliases;
    Ok(MimeInfo {
        mime,
        extension,
        aliases,
    })
}
